/**
 * Description: StudentDAOImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0 2010-03-09 李韦 created
 */
package org.paradise.dms.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.SQLQuery;
import org.paradise.dms.pojo.Swipcard;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 2010-03-09 李韦 created
 */
@Service
public class SwipcardDAOImpl extends BaseHibernateDao<Swipcard> {
	private static Logger log = Logger.getLogger(SwipcardDAOImpl.class);

	/**
	 * 
	 * Description: 增加一条刷卡记录信息
	 * 
	 * @Version1.0  2010-03-09 李韦 created
	 * @param swipcard
	 * @throws DaoException
	 */
	public void insertSwipcard(Swipcard swipcard) throws DaoException {
		this.create(swipcard);
	}
	
	/**
	 * 
	 * Description: 删除一条刷卡记录
	 * 
	 * @Version1.0 2010-03-09 李韦 created
	 * @param swipcardid
	 * @return
	 */
	public boolean deleteSwipcard(int swipcardid) {
		Swipcard swipcard = new Swipcard();
		swipcard.setId(swipcardid);
		try {
			this.delete(swipcard);
			return true;
		} catch (Exception e) {
			log.error("DMS_error_" + e);
			return false;
		}
	}
	
	/**
	 * 
	 * Description: 取得一条刷卡记录
	 * 
	 * @Version1.0 2010-03-09 李韦 created
	 * @param swipcardid
	 *            刷卡记录的ID值
	 * @return
	 * @throws DaoException
	 */
	@SuppressWarnings("unchecked")
	public List<Swipcard> getSwipcard(int swipcardid)
			throws DaoException {
		return this
				.find(
						"from Swipcard where id = ? ",
						new Object[] { swipcardid });
	}


	/**
	 * 
	 * Description: 取得所有刷卡记录
	 * 
	 * @Version1.0 2010-03-09 李韦 created
	 * @return
	 * @throws DaoException
	 */

	@SuppressWarnings("unchecked")
	public List<Swipcard> getSwipcards(String hostname) throws DaoException {
		return this.find("from Swipcard where hostname = ? order by  swiptime DESC limit 0,10",new Object[] { hostname });
		
		
//		SQLQuery query = (SQLQuery) this.getSession().createSQLQuery(
//				"select * from Swipcard order by  swiptime DESC limit 0,10").addEntity(
//						Swipcard.class);
//
//		return query.list();
	}
}